package org.gap.dao;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.gap.domain.RolesTiers;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage RolesTiers entities.
 * 
 */
@Repository("RolesTiersDAO")
@Transactional
public class RolesTiersDAOImpl extends AbstractJpaDao<RolesTiers> implements
		RolesTiersDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { RolesTiers.class }));

	/**
	 * EntityManager injected by Spring for persistence unit 
	 *
	 */
	@PersistenceContext(unitName = "")
	private EntityManager entityManager;

	/**
	 * Instantiates a new RolesTiersDAOImpl
	 *
	 */
	public RolesTiersDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findRolesTiersByRotDateFinBefore
	 *
	 */
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotDateFinBefore(java.util.Calendar rotDateFin) throws DataAccessException {

		return findRolesTiersByRotDateFinBefore(rotDateFin, -1, -1);
	}

	/**
	 * JPQL Query - findRolesTiersByRotDateFinBefore
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotDateFinBefore(java.util.Calendar rotDateFin, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRolesTiersByRotDateFinBefore", startResult, maxRows, rotDateFin);
		return new LinkedHashSet<RolesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRolesTiersByRotRole
	 *
	 */
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotRole(String rotRole) throws DataAccessException {

		return findRolesTiersByRotRole(rotRole, -1, -1);
	}

	/**
	 * JPQL Query - findRolesTiersByRotRole
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotRole(String rotRole, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRolesTiersByRotRole", startResult, maxRows, rotRole);
		return new LinkedHashSet<RolesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findAllRolesTierss
	 *
	 */
	@Transactional
	public Set<RolesTiers> findAllRolesTierss() throws DataAccessException {

		return findAllRolesTierss(-1, -1);
	}

	/**
	 * JPQL Query - findAllRolesTierss
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RolesTiers> findAllRolesTierss(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllRolesTierss", startResult, maxRows);
		return new LinkedHashSet<RolesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRolesTiersByRotDateFinAfter
	 *
	 */
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotDateFinAfter(java.util.Calendar rotDateFin) throws DataAccessException {

		return findRolesTiersByRotDateFinAfter(rotDateFin, -1, -1);
	}

	/**
	 * JPQL Query - findRolesTiersByRotDateFinAfter
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotDateFinAfter(java.util.Calendar rotDateFin, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRolesTiersByRotDateFinAfter", startResult, maxRows, rotDateFin);
		return new LinkedHashSet<RolesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRolesTiersByRotDateDebut
	 *
	 */
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotDateDebut(java.util.Calendar rotDateDebut) throws DataAccessException {

		return findRolesTiersByRotDateDebut(rotDateDebut, -1, -1);
	}

	/**
	 * JPQL Query - findRolesTiersByRotDateDebut
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotDateDebut(java.util.Calendar rotDateDebut, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRolesTiersByRotDateDebut", startResult, maxRows, rotDateDebut);
		return new LinkedHashSet<RolesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRolesTiersByRotDescriptif
	 *
	 */
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotDescriptif(String rotDescriptif) throws DataAccessException {

		return findRolesTiersByRotDescriptif(rotDescriptif, -1, -1);
	}

	/**
	 * JPQL Query - findRolesTiersByRotDescriptif
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotDescriptif(String rotDescriptif, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRolesTiersByRotDescriptif", startResult, maxRows, rotDescriptif);
		return new LinkedHashSet<RolesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRolesTiersByRotRoleContaining
	 *
	 */
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotRoleContaining(String rotRole) throws DataAccessException {

		return findRolesTiersByRotRoleContaining(rotRole, -1, -1);
	}

	/**
	 * JPQL Query - findRolesTiersByRotRoleContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotRoleContaining(String rotRole, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRolesTiersByRotRoleContaining", startResult, maxRows, rotRole);
		return new LinkedHashSet<RolesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRolesTiersByRotDescriptifContaining
	 *
	 */
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotDescriptifContaining(String rotDescriptif) throws DataAccessException {

		return findRolesTiersByRotDescriptifContaining(rotDescriptif, -1, -1);
	}

	/**
	 * JPQL Query - findRolesTiersByRotDescriptifContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotDescriptifContaining(String rotDescriptif, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRolesTiersByRotDescriptifContaining", startResult, maxRows, rotDescriptif);
		return new LinkedHashSet<RolesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRolesTiersByPrimaryKey
	 *
	 */
	@Transactional
	public RolesTiers findRolesTiersByPrimaryKey(String rotRole, Integer rotTiers) throws DataAccessException {

		return findRolesTiersByPrimaryKey(rotRole, rotTiers, -1, -1);
	}

	/**
	 * JPQL Query - findRolesTiersByPrimaryKey
	 *
	 */

	@Transactional
	public RolesTiers findRolesTiersByPrimaryKey(String rotRole, Integer rotTiers, int startResult, int maxRows) throws DataAccessException {
		try {
			return executeQueryByNameSingleResult("findRolesTiersByPrimaryKey", rotRole, rotTiers);
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findRolesTiersByRotTiers
	 *
	 */
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotTiers(Integer rotTiers) throws DataAccessException {

		return findRolesTiersByRotTiers(rotTiers, -1, -1);
	}

	/**
	 * JPQL Query - findRolesTiersByRotTiers
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotTiers(Integer rotTiers, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRolesTiersByRotTiers", startResult, maxRows, rotTiers);
		return new LinkedHashSet<RolesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRolesTiersByRotDateFin
	 *
	 */
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotDateFin(java.util.Calendar rotDateFin) throws DataAccessException {

		return findRolesTiersByRotDateFin(rotDateFin, -1, -1);
	}

	/**
	 * JPQL Query - findRolesTiersByRotDateFin
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotDateFin(java.util.Calendar rotDateFin, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRolesTiersByRotDateFin", startResult, maxRows, rotDateFin);
		return new LinkedHashSet<RolesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRolesTiersByRotDateDebutBefore
	 *
	 */
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotDateDebutBefore(java.util.Calendar rotDateDebut) throws DataAccessException {

		return findRolesTiersByRotDateDebutBefore(rotDateDebut, -1, -1);
	}

	/**
	 * JPQL Query - findRolesTiersByRotDateDebutBefore
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotDateDebutBefore(java.util.Calendar rotDateDebut, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRolesTiersByRotDateDebutBefore", startResult, maxRows, rotDateDebut);
		return new LinkedHashSet<RolesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRolesTiersByRotDateDebutAfter
	 *
	 */
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotDateDebutAfter(java.util.Calendar rotDateDebut) throws DataAccessException {

		return findRolesTiersByRotDateDebutAfter(rotDateDebut, -1, -1);
	}

	/**
	 * JPQL Query - findRolesTiersByRotDateDebutAfter
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RolesTiers> findRolesTiersByRotDateDebutAfter(java.util.Calendar rotDateDebut, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRolesTiersByRotDateDebutAfter", startResult, maxRows, rotDateDebut);
		return new LinkedHashSet<RolesTiers>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(RolesTiers entity) {
		return true;
	}
}
